<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>
          <i class="el-icon-lx-calendar"></i> 表单
        </el-breadcrumb-item>
        <el-breadcrumb-item>添加学校</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <div class="form-box">
        <el-form ref="school"
                 :model="school"
                 label-width="80px">
          <el-form-item label="学校名称">
            <el-input v-model="school.name"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary"
                       @click="onSubmit">添加</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
    name: 'baseform',
    data() {
        return {
            school: {
                id: '',
                name: ''
            }
        };
    },
    methods: {
        onSubmit() {
            if (this.school.name == null || this.school.name == '') {
                this.$message({
                    type: 'error',
                    message: '学校名称不能为空'
                });
            } else {
                this.$axios.post('/manage/admin/school/addSchool', this.school).then((r) => {
                    if (r.data.code == 200) {
                        this.$message.success('添加成功');
                        this.school.id = null;
                        this.school.name = null;
                    } else {
                        this.$message.warning('添加失败');
                    }
                });
            }
        }
    }
};
</script>